<?php
/**
 * Interface to add/remove Terms from the system
 * Simple example of using MADAL to create a Add, Update, Delete interface for a single table
 */
?>
<html>
<head>
<?php
require_once '../dbms_university_courses_mvc/Model/model_require_once.php';
?>
</head>
<body>
<h2>Existing Terms</h2>
<?php
$terms = Term::getTerms();
//Setup the Terms Javascript objects, these objects are required for updates and delections of the underlying database rows
Term::instantiate_javascript_objects($terms);

?>

<table>
	<tr>
		<th>Term</th>
		<th>Year</th>
	</tr>
<?php
//Iterate through the terms and print an input setter and delete button for each
//Refresh the page content on deletion
//refreshPage/reloadPage functions can be found in the js_include/index_functions.js page
//refreshPage could easily reload a much smaller portion of the page
foreach ( $terms as $term ) {
	?>
	<tr>
		<td><?php
	echo $term->print_term_input_setter();
	?></td>
		<td><?php
	echo $term->print_year_input_setter();
	?></td>
	<td><?php $term->print_delete_button(true, "refreshPage");?></td>
	</tr>
	<?php
}

//insert new course via ajax call
?>
</table>
<br><br>
<h2>Add New Term</h2>
<?php 
//print a button that will display all the properties except the primary key for adding a term
//on add, refresh the page
Term::print_Term_add("refreshPage");?>

</body>
</html>